package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import javax.swing.JComponent;
import model.*;

public class NextPointOfInterestViewDecorator extends ViewDecorator implements Observer {

    private Map map;
    private PointOfInterestWatcher poiWatcher;
    
    public NextPointOfInterestViewDecorator(JComponent component, Map map, PointOfInterestWatcher poiWatcher) {
        super(component);
        this.map = map;
        this.poiWatcher = poiWatcher;
        this.poiWatcher.attach(this);
    }
    
    @Override
    public void update() {
        this.repaint();
    }
    
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D)g;
        
        // Pak het coordinaat van de point of interest
        RouteWaypoint waypoint = poiWatcher.getNextWaypoint();
        Point coordPoint = new Point(MapViewUtil.calculateXpixels(map, waypoint.getGpsCoordinate()),
                                    MapViewUtil.calculateYpixels(map, waypoint.getGpsCoordinate()));
        
        // Maak een polygon die de pijl voorsteld
        Polygon marker = new Polygon();
        marker.addPoint(coordPoint.x, coordPoint.y);
        marker.addPoint(coordPoint.x - 12, coordPoint.y - 23);
        marker.addPoint(coordPoint.x + 12, coordPoint.y - 23);
        
        // Teken de binnenkan van de pijl
        g2d.setColor(Color.GREEN);
        g2d.fillPolygon(marker);
        
        // Teken een lijn er omheen
        g2d.setColor(Color.DARK_GRAY);
        g2d.draw(marker);
    }
}
